package com.portlet.controller;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.portlet.model.nguyenlieu;
import com.portlet.model.nlhassp;
import com.portlet.model.quycachSP;
import com.portlet.service.nguyenlieuLocalServiceUtil;
import com.portlet.service.nlhasspLocalServiceUtil;
import com.portlet.service.quycachSPLocalServiceUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

public class qlyNLQC extends MVCPortlet {
	public void addNL(ActionRequest actionRequest, ActionResponse actionResponse)
			throws SystemException {
		String maNL = actionRequest.getParameter("MaNL");
		String tenNL = actionRequest.getParameter("TenNL");
		String ghiChu = actionRequest.getParameter("GhiChu");

		nguyenlieu nl = nguyenlieuLocalServiceUtil.createnguyenlieu(maNL);
		nl.setTenNguyenLieu(tenNL);
		nl.setGhiChu(ghiChu);

		nguyenlieuLocalServiceUtil.addnguyenlieu(nl);
		System.out.println("Them thanh cong nguyen lieu");
		actionResponse.setRenderParameter("JspPage", "/view.jsp");
	}

	public void addQC(ActionRequest actionRequest, ActionResponse actioResponse)
			throws SystemException {
		String maQC = actionRequest.getParameter("maQC");
		String tenQC = actionRequest.getParameter("tenQC");

		quycachSP qc = quycachSPLocalServiceUtil.createquycachSP(maQC);
		qc.setTenQC(tenQC);
		quycachSPLocalServiceUtil.addquycachSP(qc);
		System.out.println("Them quy cach thanh cong");
		actioResponse.setRenderParameter("jspPage", "/view.jsp");
	}
	public void addNLQC(ActionRequest actionRequest,
					ActionResponse actionResponse) throws SystemException{
		String maNLQC=actionRequest.getParameter("maNLQC");
		String maQC=actionRequest.getParameter("maQC");
		String maNL=actionRequest.getParameter("maNL");
		String quycach=actionRequest.getParameter("quycach");
		String tieuchikiemtra=actionRequest.getParameter("tieuchikiemtra");
		String cachkiemtra=actionRequest.getParameter("cachkiemtra");
		
		nlhassp nlqc=nlhasspLocalServiceUtil.createnlhassp(Long.parseLong(maNLQC));
		nlqc.setMaNguyenLieu(maNL);
		nlqc.setMaQC(maQC);
		nlqc.setQuyCach(quycach);
		nlqc.setTieuChiKiemTra(tieuchikiemtra);
		nlqc.setCachKiemTra(cachkiemtra);
		nlhasspLocalServiceUtil.addnlhassp(nlqc);
		System.out.println("Them chi tiet quy trinh thanh cong");
		actionResponse.setRenderParameter("jspPage", "/viewNLQC.jsp");
	}
	
	public void editNL(ActionRequest actionRequest,
			ActionResponse actionResponse) throws PortalException,
			SystemException {
		String maNL = actionRequest.getParameter("maNL");
		nguyenlieu nl = nguyenlieuLocalServiceUtil.getnguyenlieu(maNL);

		System.out.println(nl.toString());
		actionRequest.setAttribute("edit", nl);
		actionResponse.setRenderParameter("jspPage", "/edit.jsp");
	}

	public void editQC(ActionRequest actionRequest,
			ActionResponse actionResponse) throws PortalException,
			SystemException {
		String maQC = actionRequest.getParameter("maQC");
		quycachSP qc = quycachSPLocalServiceUtil.getquycachSP(maQC);

		System.out.println(qc.toString());
		actionRequest.setAttribute("edit", qc);
		actionResponse.setRenderParameter("jspPage", "/editQC.jsp");
	}
	public void editNLQC(ActionRequest actionRequest,
					ActionResponse actionResponse) throws NumberFormatException, PortalException, SystemException{
		String maNLQC=actionRequest.getParameter("maNLQC");
		nlhassp nlqc=nlhasspLocalServiceUtil.getnlhassp(Long.parseLong(maNLQC));
		
		actionRequest.setAttribute("edit", nlqc);
		actionResponse.setRenderParameter("jspPage","/editNLQC.jsp");
	}
	public void updatenameURL(ActionRequest actionRequest,
			ActionResponse actionResponse) throws PortalException,
			SystemException {
		String maNL = actionRequest.getParameter("maNL");
		String tenNL = actionRequest.getParameter("tenNL");
		String ghiChu = actionRequest.getParameter("ghiChu");

		nguyenlieu nl = nguyenlieuLocalServiceUtil.getnguyenlieu(maNL);
		nl.setTenNguyenLieu(tenNL);
		nl.setGhiChu(ghiChu);
		nguyenlieuLocalServiceUtil.updatenguyenlieu(nl);

		System.out.println("Cap nhat thanh cong");
		actionResponse.setRenderParameter("jspPage", "/view.jsp");
	}

	public void updateQCURL(ActionRequest actionRequest,
			ActionResponse actionResponse) throws PortalException,
			SystemException {
		String maQC = actionRequest.getParameter("maQC");
		String tenQC = actionRequest.getParameter("tenQC");

		quycachSP qc = quycachSPLocalServiceUtil.getquycachSP(maQC);
		qc.setTenQC(tenQC);

		quycachSPLocalServiceUtil.updatequycachSP(qc);
		System.out.println("Cap nhat thanh cong");
		actionResponse.setRenderParameter("jspPage", "/viewQC.jsp");
	}
	public void updateNLQCURL(ActionRequest actionRequest, 
						ActionResponse actionResponse) throws NumberFormatException, PortalException, SystemException{
		String maNLQC=actionRequest.getParameter("maNLQC");
		String quycach=actionRequest.getParameter("quycach");
		String tieuchi=actionRequest.getParameter("tieuchi");
		String cachkt=actionRequest.getParameter("cachkt");
		
		nlhassp nlqc=nlhasspLocalServiceUtil.getnlhassp(Long.parseLong(maNLQC));
		nlqc.setQuyCach(quycach);
		nlqc.setTieuChiKiemTra(tieuchi);
		nlqc.setCachKiemTra(cachkt);
		nlhasspLocalServiceUtil.updatenlhassp(nlqc);
		
		System.out.println("Cap nhat thanh cong");
		actionResponse.setRenderParameter("jspPage", "/viewNLQC.jsp");
	}
	public void deleteNL(ActionRequest actionResquest,
			ActionResponse actionresponse) throws PortalException,
			SystemException {
		String maNL = actionResquest.getParameter("edit");
		nguyenlieu nl = nguyenlieuLocalServiceUtil.getnguyenlieu(maNL);
		nguyenlieuLocalServiceUtil.deletenguyenlieu(nl);

		System.out.println("Xoa thanh cong");
		actionresponse.setRenderParameter("jspPage", "/view.jsp");
	}

	public void deleteQC(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException,
			SystemException {
		String maQC = actionRequest.getParameter("edit1");
		quycachSP qc = quycachSPLocalServiceUtil.getquycachSP(maQC);

		quycachSPLocalServiceUtil.deletequycachSP(qc);
		System.out.println("Xoa quy cach thanh cong");
		actionResponse.setRenderParameter("jspPage", "/viewQC.jsp");
	}
	public void deleteNLQC(ActionRequest actionRequest, 
			ActionResponse actionResponse) throws NumberFormatException, PortalException, SystemException{
		String nlqc=actionRequest.getParameter("delete");
		nlhassp nl1= nlhasspLocalServiceUtil.getnlhassp(Long.parseLong(nlqc));
		nlhasspLocalServiceUtil.deletenlhassp(nl1);
		
		System.out.println("Xoa thanh cong");
		actionResponse.setRenderParameter("jspPage", "/viewNLQC.jsp");
	}
}
